#include<stdio.h>
#include<string.h>

//定义结构体
struct Books{
    char title[50];
    char author[50];
    char subject[50];
    int book_id;
};

//声明1，可以在定义的时候声明
struct A{
    char name[10];
}a = {"allen"};

void printStruct(struct Books b);

int main(){
    //声明2,
    struct Books book1;
    strcpy(book1.title, "c program language");
    strcpy(book1.author, "allen");
    strcpy(book1.subject, "中文");
    book1.book_id = 1;

    printf("title = %s, author = %s, subject = %s, book_id = %d\n", book1.title, book1.author, book1.subject, book1.book_id);

    //结构体作为参数
    printStruct(book1);

    //结构体类型的指针
    //使用结构体指针的时候，不需要像其他指针变量在前面加上*号，而且不能用点好.指示成员，应该用->指示成员。！！！！
    struct Books *book_ptr;
    book_ptr = &book1;
    printf("ptr => title = %s, author = %s, subject = %s, book_id = %d\n", book_ptr->title, book_ptr->author, book_ptr->subject, book_ptr->book_id);
}

void printStruct(struct Books b){
    printf("func => title = %s, author = %s, subject = %s, book_id = %d\n", b.title, b.author, b.subject, b.book_id);
}